// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsInstanceCollection.
//   $Id$
#pragma once

#include "resource.h"
#include "XForms.h"
#include <map>

class ATL_NO_VTABLE CXFormsInstanceCollection : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CXFormsInstanceCollection, &CLSID_XFormsInstanceCollection>,
	public IDispatchImpl<IXFormsInstanceCollection, &IID_IXFormsInstanceCollection, &LIBID_XFORMSLib, 1, 16>
{
public:
	CXFormsInstanceCollection();
	~CXFormsInstanceCollection();

	DECLARE_REGISTRY_RESOURCEID(IDR_XFORMSINSTANCECOLLECTION)

	BEGIN_COM_MAP(CXFormsInstanceCollection)
		COM_INTERFACE_ENTRY(IXFormsInstanceCollection)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()

	STDMETHOD(get_length)(long* pVal);
	STDMETHOD(GetItem)(long nIndex, IXMLDOMDocument **ppInstance);
	STDMETHOD(GetItemById)(BSTR sId, IXMLDOMDocument **ppInstance);

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct();
	void FinalRelease();

	void AddInstance(BSTR sId, IXMLDOMDocument *pInstance);

private:
	CXFormsInstanceCollection(const CXFormsInstanceCollection &rhs);
	CXFormsInstanceCollection &operator=(const CXFormsInstanceCollection &rhs);

	typedef std::multimap<CComBSTR, CComQIPtr<IXMLDOMDocument> > instancemap_t;
	typedef std::pair<CComBSTR, CComQIPtr<IXMLDOMDocument> > instancemapentry_t;

	instancemap_t m_Collection;
};


OBJECT_ENTRY_AUTO(__uuidof(XFormsInstanceCollection), CXFormsInstanceCollection)
